package com.tro;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 自定义拦截器
 * @author apple
 *
 */
public class CommonInterceptor extends HandlerInterceptorAdapter{
	public static Logger logger = LoggerFactory.getLogger(CommonInterceptor.class);  
	
    @Override    
    public boolean preHandle(HttpServletRequest request,    
            HttpServletResponse response, Object handler) throws Exception {    
       
        logger.info("进入拦截器");    
        String requestUri = request.getRequestURI();  
        String contextPath = request.getContextPath();  
        String url = requestUri.substring(contextPath.length());  
        
        logger.info("requestUri:"+requestUri);    
        logger.info("contextPath:"+contextPath);    
        logger.info("url:"+url);    
          
        
            return true;     
    }    
    
    
    @Override    
    public void postHandle(HttpServletRequest request,    
            HttpServletResponse response, Object handler,    
            ModelAndView modelAndView) throws Exception {    
    	logger.info("在业务处理器处理请求执行完成后,生成视图之前执行的动作");    
      
    }    
        
    @Override    
    public void afterCompletion(HttpServletRequest request,    
            HttpServletResponse response, Object handler, Exception ex)    
            throws Exception {    
        logger.info("在DispatcherServlet完全处理完请求后被调用");    
    }    
}
